
let ignoreKeys = ["ThemeName","IsSecondOpen","UserAccount","UserData","UserInfo"];

function Set(key,value){
	let str = JSON.stringify(value);
	let res = uni.setStorageSync(key,str);
	console.log('storage set:',res);
	// uni.setStorage({
	// 	key:key,
	// 	data:str,
	// 	success(e) {
	// 		console.log('storage set:',e);
	// 	},
	// 	fail(e) {
	// 		console.log('storage set fail:',e);
	// 	}
	// })
}

function Get(key,callFunc){
	
	let res = uni.getStorageSync(key);
	console.log('storage get:',res!=null);
	if(res){
		let data = JSON.parse(res);
		return data;
	}
	
	return res;
	// uni.getStorageSync({
	// 	key,
	// 	success(e) {
	// 		console.log('storage set:',e);
	// 		let data = JSON.parse(e);
	// 		callFunc(data);
	// 	},
	// 	fail(e) {
	// 		console.log('storage set fail:',e);
	// 	}
	// })
}
function GetUserAccount(){
	
	return Get('UserAccount');
}

function SetUserAccount(data){
	Set('UserAccount',data)
}

function ClearUserAccount(){
	uni.removeStorageSync('UserAccount');
	console.log("清除，，",uni.getStorageSync("UserAccount"))
	
}
function GetUserData(){
	
	return Get('UserData');
}

function SetUserData(data){
	Set('UserData',data)
}

function ClearUserData(){
	uni.removeStorageSync('UserData');
}


function GetUserInfo(){
	
	return Get('UserInfo');
}

function SetUserInfo(data){
	Set('UserInfo',data)
}

function ClearUserInfo(){
	uni.removeStorageSync('UserInfo');
}

function ClearStorage(){
	let sinfo = uni.getStorageInfoSync();
	if(sinfo){
		
		sinfo.keys.forEach(x=>{
			let idx = ignoreKeys.findIndex(y=>x==y);
			console.log('storage keys:',idx,x);
			if(idx<0){
				uni.removeStorageSync(x);
			}
		});
		return true;
		
	}else{
		return false;
	}
}

export default {
	Get,Set,GetUserAccount,GetUserData,SetUserAccount,SetUserData,ClearStorage,ClearUserAccount,ClearUserData,
	GetUserInfo,SetUserInfo,ClearUserInfo
}